package com.andy.base.util;

public class UrlSplitUtil {

    /**
     * 去除协议头
     * @param url
     * @return
     */
    public static String rmProtocolHead(String url){
        int index = url.indexOf("://");
        if (index != -1) {
            url = url.substring(index + 3);
        }
        return url;
    }

    /**
     * 拿到host
     * @param url
     * @return
     */
    public static String getHost(String url) {
        String host = "";

        //去除协议头
        url = rmProtocolHead(url);

        //拿到host
        int index = url.indexOf("/");
        if (index != -1) {
            host = url.substring(0, index);
        }

        return host;
    }


    public static String getContext(String url) {
        String context = "";

        //去除协议头
        url = rmProtocolHead(url);

        //去掉host
        int index = url.indexOf("/");
        if (index == -1) return context;
        url = url.substring(index+1);

        //拿到context
        index = url.indexOf("/");
        if (index == -1) return context;
        context = url.substring(0, index);

        return context;
    }

    public static String getWrapper(String url) {
        String wrapper = "";

        //去除协议头
        url = rmProtocolHead(url);

        //去掉host
        int index = url.indexOf("/");
        if (index == -1) return wrapper;
        url = url.substring(index+1);

        //去掉context
        index = url.indexOf("/");
        if (index == -1) return wrapper;
        wrapper = url.substring(index);

        return wrapper;
    }

    public static void main(String[] args){
        String url = "https://blog.csdn.net/tianya111cy/article/details/84208547";

        System.out.println(getWrapper(url));


    }


    
    
}
